package singleton;/** * Created by Administrator on 2018-10-23. * 使用双重加锁，在getInstance()中减少使用同步。 */public class Singleton2 {    //volatile 关键字确保当uniqueInstance 变量被初始化承Singleton2 实例时，多个线程正确的处理uniqueInstance 变量    private  volatile static Singleton2 uniqueInstance;    private Singleton2(){}    public static Singleton2 getInstance()    {        if(uniqueInstance == null){            synchronized (Singleton2.class){                if(uniqueInstance ==null){                    uniqueInstance = new Singleton2();                }            }        }        return uniqueInstance;    }}